package com.kexio.enterprise.governance.circuitbreaker.config;

import com.kexio.enterprise.governance.circuitbreaker.enums.SlidingWindowType;

import java.util.List;
import java.util.Map;

/**
 * 熔断器配置
 * 
 * @author Kexio
 * @since 1.0.0
 */
public class CircuitBreakerConfig {
    private int failureThreshold; // 失败阈值
    private double failureRate; // 失败率阈值（0.0-1.0）
    private int minimumNumberOfCalls; // 最小调用次数
    private long waitDurationInOpenStateMs; // 开启状态等待时间
    private int permittedNumberOfCallsInHalfOpenState; // 半开状态允许调用次数
    private long timeoutMs; // 超时时间
    private boolean automaticTransitionFromOpenToHalfOpenEnabled; // 自动从开启到半开
    private int slidingWindowSize; // 滑动窗口大小
    private SlidingWindowType slidingWindowType; // 滑动窗口类型
    private List<Class<? extends Throwable>> recordExceptions; // 记录的异常类型
    private List<Class<? extends Throwable>> ignoreExceptions; // 忽略的异常类型
    private boolean enableStatistics; // 是否启用统计
    private Map<String, Object> customParams; // 自定义参数

    public CircuitBreakerConfig() {
        this.failureThreshold = 5;
        this.failureRate = 0.5;
        this.minimumNumberOfCalls = 10;
        this.waitDurationInOpenStateMs = 60000; // 1分钟
        this.permittedNumberOfCallsInHalfOpenState = 3;
        this.timeoutMs = 5000; // 5秒
        this.automaticTransitionFromOpenToHalfOpenEnabled = true;
        this.slidingWindowSize = 100;
        this.slidingWindowType = SlidingWindowType.COUNT_BASED;
        this.enableStatistics = true;
    }

    // Getters and Setters
    public int getFailureThreshold() { return failureThreshold; }
    public void setFailureThreshold(int failureThreshold) { this.failureThreshold = failureThreshold; }
    
    public double getFailureRate() { return failureRate; }
    public void setFailureRate(double failureRate) { this.failureRate = failureRate; }
    
    public int getMinimumNumberOfCalls() { return minimumNumberOfCalls; }
    public void setMinimumNumberOfCalls(int minimumNumberOfCalls) { this.minimumNumberOfCalls = minimumNumberOfCalls; }
    
    public long getWaitDurationInOpenStateMs() { return waitDurationInOpenStateMs; }
    public void setWaitDurationInOpenStateMs(long waitDurationInOpenStateMs) { this.waitDurationInOpenStateMs = waitDurationInOpenStateMs; }
    
    public int getPermittedNumberOfCallsInHalfOpenState() { return permittedNumberOfCallsInHalfOpenState; }
    public void setPermittedNumberOfCallsInHalfOpenState(int permittedNumberOfCallsInHalfOpenState) { this.permittedNumberOfCallsInHalfOpenState = permittedNumberOfCallsInHalfOpenState; }
    
    public long getTimeoutMs() { return timeoutMs; }
    public void setTimeoutMs(long timeoutMs) { this.timeoutMs = timeoutMs; }
    
    public boolean isAutomaticTransitionFromOpenToHalfOpenEnabled() { return automaticTransitionFromOpenToHalfOpenEnabled; }
    public void setAutomaticTransitionFromOpenToHalfOpenEnabled(boolean automaticTransitionFromOpenToHalfOpenEnabled) { this.automaticTransitionFromOpenToHalfOpenEnabled = automaticTransitionFromOpenToHalfOpenEnabled; }
    
    public int getSlidingWindowSize() { return slidingWindowSize; }
    public void setSlidingWindowSize(int slidingWindowSize) { this.slidingWindowSize = slidingWindowSize; }
    
    public SlidingWindowType getSlidingWindowType() { return slidingWindowType; }
    public void setSlidingWindowType(SlidingWindowType slidingWindowType) { this.slidingWindowType = slidingWindowType; }
    
    public List<Class<? extends Throwable>> getRecordExceptions() { return recordExceptions; }
    public void setRecordExceptions(List<Class<? extends Throwable>> recordExceptions) { this.recordExceptions = recordExceptions; }
    
    public List<Class<? extends Throwable>> getIgnoreExceptions() { return ignoreExceptions; }
    public void setIgnoreExceptions(List<Class<? extends Throwable>> ignoreExceptions) { this.ignoreExceptions = ignoreExceptions; }
    
    public boolean isEnableStatistics() { return enableStatistics; }
    public void setEnableStatistics(boolean enableStatistics) { this.enableStatistics = enableStatistics; }
    
    public Map<String, Object> getCustomParams() { return customParams; }
    public void setCustomParams(Map<String, Object> customParams) { this.customParams = customParams; }
}
